#include "auto_shoot.h"

extern UART_HandleTypeDef huart1;
extern DMA_HandleTypeDef hdma_usart1_rx;

uint8_t RX_buf[RX_BUF_NUM];
autotype recd;

void AUTO_init(void)
{
		__HAL_UART_ENABLE_IT(&huart1,UART_IT_IDLE);
	  HAL_UART_Receive_DMA(&huart1,RX_buf,RX_BUF_NUM);
}

void UART1_receive_IDE(void)
{
		HAL_UART_DMAStop(&huart1);
		uint8_t  date_length = RX_BUF_NUM - __HAL_DMA_GET_COUNTER(&hdma_usart1_rx);
	  if( date_length== DATE_LENGTH )
		{
			HAL_UART_Transmit(&huart1, RX_buf, 10, 100);
			memcpy(recd.buf, RX_buf, DATE_LENGTH);
		}
		memset(RX_buf, 0, RX_BUF_NUM );
		HAL_UART_Receive_DMA(&huart1,  RX_buf, RX_BUF_NUM);
}



void USART1_IRQHandler(void)
{
  /* USER CODE BEGIN USART1_IRQn 0 */
	if(RESET != __HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE))
	{
		__HAL_UART_CLEAR_IDLEFLAG(&huart1);
		UART1_receive_IDE();
		
	}
  /* USER CODE END USART1_IRQn 0 */
   HAL_UART_IRQHandler(&huart1);
  /* USER CODE BEGIN USART1_IRQn 1 */

  /* USER CODE END USART1_IRQn 1 */
}

CTRL  *get_AUTOshoot_point(void)
{
		return &recd.rec;
	
}
